package OrderService

import (
	"context"
	"gdshop-font-api-go/app/request/OrderReq"
	"gdshop-font-api-go/library/response"
	"gdshop-font-api-go/library/tools"
	"gdshop-font-api-go/rpc/request"
	"gdshop-font-api-go/rpc/service"
	_ "github.com/hprose/hprose-golang/rpc/fasthttp"
)

// 用户关闭订单 判断状态，必须是 1待付款 才可以关闭订单
func Close(ctx context.Context, parames *OrderReq.Close) *response.JsonResponse {
	if !IsMyOrder(ctx, parames.Id, int(parames.MemberId)) {
		return response.FailByRequestMessage(nil, "请勿操作别人的订单")
	}
	/*tmp := g.Map{
		"order_id":  parames.Id,
		"member_id": parames.MemberId,
		"remark":    parames.Remark,
	}
	hash := guid.S()
	_, err := g.Redis().Do("SETEX", "MemberCloseOrder:"+hash, 60, tmp)
	if err != nil {
		return response.FailByRequestMessage(nil, err.Error())
	}
	var jieguo *response.JsonResponse
	err = g.Client().GetVar(g.Cfg().GetString("back_api.MemberCloseOrderUrl"), g.Map{
		"hash": hash,
	}).Struct(&jieguo)
	if err != nil {
		return response.FailByRequestMessage(nil, err.Error())
	}
	return jieguo*/

	client := tools.GetRpcClient()
	var orderService *service.OrderService
	client.UseService(&orderService)
	jieguo, err := orderService.MemberCloseOrder(&request.MemberCloseOrder{
		OrderId:  parames.Id,
		MemberId: parames.MemberId,
		Remark:   parames.Remark,
	})
	if err != nil {
		return response.RpcFailByRequestMessage(nil, err.Error())
	}

	return jieguo
}
